<?php
/**
 *微信sdk
 */
namespace App\Controller\Index;
use Think\Cache\Driver\Redis;
use Think\Controller;
use Think\Wxpay\Wxpay;

class WxController extends Controller{
    /**
     * 获取微信获取jsApi
     */

    public function getJsSdk(){
        $wxpay = new Wxpay();
        $info = $wxpay->getJsSdk();
        $this->ajaxReturn(['code'=>200,'info'=>$info,'url'=>I('param.url')]);
    }


    /**
     * 判断是否登录
     */
    public function is_login(){
        $token = I('param.token');
        $member_id = session('member_id');
        if(empty($member_id)){
            if($token){
                $id = authcode($token,'DECODE');
                session('member_id',$id);
            }
        }
        if(empty($member_id)){
            $this->ajaxReturn(['code'=>301,'msg'=>'你还未登录']);
        }else{
            $this->ajaxReturn(['code'=>200,'shop_id'=>$member_id,'token'=>$token]);
        }
    }

    /**
     * 获取JS接口临时票据
     */
    public function getJsApiTicket(){
        $wxpay = new Wxpay();
        $ticket = $wxpay->getJsApiTicket();
        $this->ajaxReturn(['code'=>200,'jsApiTicket'=>$ticket]);
    }
    /**
     * 微信推送
     */
    public function msgPush($memberId,$msgType,$msgJson){
        $msg = new MsgPushController();
        $res = $msg->msgPush($memberId, $msgType, $msgJson);
        $this->ajaxReturn(['code'=>200,'res'=>$res]);
    }
}
